﻿using System;
using Microsoft.Xna.Framework;
using Terraria.World.Generation;

namespace Terraria.GameContent.Biomes
{
	// Token: 0x0200044B RID: 1099
	public class CampsiteBiome : MicroBiome
	{
		// Token: 0x060025C8 RID: 9672 RVA: 0x0048A270 File Offset: 0x00488470
		public override bool Place(Point origin, StructureMap structures)
		{
			Ref<int> @ref = new Ref<int>(0);
			Ref<int> ref2 = new Ref<int>(0);
			WorldUtils.Gen(origin, new Shapes.Circle(10), Actions.Chain(new GenAction[]
			{
				new Actions.Scanner(ref2),
				new Modifiers.IsSolid(),
				new Actions.Scanner(@ref)
			}));
			if (@ref.Value < ref2.Value - 5)
			{
				return false;
			}
			int num = GenBase._random.Next(6, 10);
			int num2 = GenBase._random.Next(5);
			if (!structures.CanPlace(new Rectangle(origin.X - num, origin.Y - num, num * 2, num * 2), 0))
			{
				return false;
			}
			ShapeData data = new ShapeData();
			GenShape shape = new Shapes.Slime(num);
			GenAction[] array = new GenAction[6];
			array[0] = new Modifiers.Blotches(num2, num2, num2, 1, 0.3).Output(data);
			array[1] = new Modifiers.Offset(0, -2);
			array[2] = new Modifiers.OnlyTiles(new ushort[]
			{
				53
			});
			array[3] = new Actions.SetTile(397, true, true);
			GenAction[] array2 = array;
			int num3 = 4;
			byte[] types = new byte[1];
			array2[num3] = new Modifiers.OnlyWalls(types);
			array[5] = new Actions.PlaceWall(16, true);
			WorldUtils.Gen(origin, shape, Actions.Chain(array));
			GenShape shape2 = new ModShapes.All(data);
			GenAction[] array3 = new GenAction[5];
			array3[0] = new Actions.ClearTile(false);
			array3[1] = new Actions.SetLiquid(0, 0);
			array3[2] = new Actions.SetFrames(true);
			GenAction[] array4 = array3;
			int num4 = 3;
			byte[] types2 = new byte[1];
			array4[num4] = new Modifiers.OnlyWalls(types2);
			array3[4] = new Actions.PlaceWall(16, true);
			WorldUtils.Gen(origin, shape2, Actions.Chain(array3));
			Point point;
			if (!WorldUtils.Find(origin, Searches.Chain(new Searches.Down(10), new GenCondition[]
			{
				new Conditions.IsSolid()
			}), out point))
			{
				return false;
			}
			int num5 = point.Y - 1;
			bool flag = GenBase._random.Next() % 2 == 0;
			if (GenBase._random.Next() % 10 != 0)
			{
				int num6 = GenBase._random.Next(1, 4);
				int num7 = flag ? 4 : (-(num >> 1));
				for (int i = 0; i < num6; i++)
				{
					int num8 = GenBase._random.Next(1, 3);
					for (int j = 0; j < num8; j++)
					{
						WorldGen.PlaceTile(origin.X + num7 - i, num5 - j, 331, false, false, -1, 0);
					}
				}
			}
			int num9 = (num - 3) * (flag ? -1 : 1);
			if (GenBase._random.Next() % 10 != 0)
			{
				WorldGen.PlaceTile(origin.X + num9, num5, 186, false, false, -1, 0);
			}
			if (GenBase._random.Next() % 10 != 0)
			{
				WorldGen.PlaceTile(origin.X, num5, 215, true, false, -1, 0);
				if (GenBase._tiles[origin.X, num5].active() && GenBase._tiles[origin.X, num5].type == 215)
				{
					Tile tile = GenBase._tiles[origin.X, num5];
					Tile tile2 = tile;
					tile2.frameY += 36;
					Tile tile3 = GenBase._tiles[origin.X - 1, num5];
					Tile tile4 = tile3;
					tile4.frameY += 36;
					Tile tile5 = GenBase._tiles[origin.X + 1, num5];
					Tile tile6 = tile5;
					tile6.frameY += 36;
					Tile tile7 = GenBase._tiles[origin.X, num5 - 1];
					Tile tile8 = tile7;
					tile8.frameY += 36;
					Tile tile9 = GenBase._tiles[origin.X - 1, num5 - 1];
					Tile tile10 = tile9;
					tile10.frameY += 36;
					Tile tile11 = GenBase._tiles[origin.X + 1, num5 - 1];
					Tile tile12 = tile11;
					tile12.frameY += 36;
				}
			}
			structures.AddStructure(new Rectangle(origin.X - num, origin.Y - num, num * 2, num * 2), 4);
			return true;
		}
	}
}
